home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Pict2Ascii 1.03 / Src / (No AS) / CPict2AsciiApp.cp < prev    next >
Encoding:
Text File  |  1997-05-22  |  7.1 KB  |  228 lines  |  [TEXT/CWIE]

  1. // =================================================================================
  2. //    CPict2AsciiApp.cp                        1997 BB's Team inc. All rights reserved
  3. // =================================================================================
  4. #include "PLConstants.h"
  5. #include "CPreferences.h"
  6. #include "CDocument.h"
  7. #include "CPict2AsciiApp.h"
  8.  
  9. #include "CDynamicEditField.h"
  10. #include "CMemoryIndicator.h"
  11. #include "LDynamicPopupMenu.h"
  12. #include "CDynamicText.h"
  13. #include "CGreyCaption.h"
  14. #include "CGWorldPane.h"
  15.  
  16. // StandardGetFilePreview
  17. #include <ImageCompression.h>
  18.  
  19. #include <LGrowZone.h>
  20. #include <LMenu.h>
  21. #include <LMenuBar.h>
  22. #include <LStdControl.h>
  23. #include <LString.h>
  24. #include <UDesktop.h>
  25. #include <UDrawingState.h>
  26. #include <UMemoryMgr.h>
  27. #include <LDialogBox.h>
  28. #include <UReanimator.h>
  29. #include <URegistrar.h>
  30. #include <LEditField.h>
  31. #include <LPrintOut.h>
  32. #include <LRadioGroup.h>
  33. #include <LActiveScroller.h>
  34. #include <LGroupBox.h>
  35.  
  36. #include <PP_Messages.h>
  37.  
  38. #ifdef PL_DEBUG
  39.     #include <LSIOUXAttachment.h>
  40. #endif
  41.  
  42. // =================================================================================
  43. //        • Main Program
  44. // =================================================================================
  45. void
  46. main( void )
  47. {
  48.     // Initialize the heap. Parameter is number
  49.     // of master handle blocks to allocate.
  50.     InitializeHeap( 4 );
  51.     
  52.     // Initialize the MacOS toolbox.
  53.     UQDGlobals::InitializeToolbox( &qd );
  54.  
  55.     // Setup the throw and signal actions.
  56. #ifdef PL_DEBUG
  57.     SetDebugThrow_( debugAction_Alert );
  58.     SetDebugSignal_( debugAction_Alert );
  59. #endif
  60.  
  61.     // Install a GrowZone function to catch  low memory situations.
  62.     // Parameter is the size of the memory reserve in bytes.
  63.     new LGrowZone( 30000 );
  64.  
  65.     // Create the application object and run it.
  66.     CPict2AsciiApp    theApp;
  67.     theApp.Run();
  68. }
  69.  
  70.  
  71. // ---------------------------------------------------------------------------------
  72. //        • CPict2AsciiApp
  73. // ---------------------------------------------------------------------------------
  74. CPict2AsciiApp::CPict2AsciiApp()
  75. {
  76.     // Register PowerPlant class creator functions.
  77.     URegistrar::RegisterClass(LCaption::class_ID,        (ClassCreatorFunc) LCaption::CreateCaptionStream);
  78.     URegistrar::RegisterClass(LDialogBox::class_ID,        (ClassCreatorFunc) LDialogBox::CreateDialogBoxStream);
  79.     URegistrar::RegisterClass(LEditField::class_ID,        (ClassCreatorFunc) LEditField::CreateEditFieldStream);
  80.     URegistrar::RegisterClass(LPane::class_ID,            (ClassCreatorFunc) LPane::CreatePaneStream);
  81.     URegistrar::RegisterClass(LPlaceHolder::class_ID,    (ClassCreatorFunc) LPlaceHolder::CreatePlaceHolderStream);
  82.     URegistrar::RegisterClass(LPrintout::class_ID,        (ClassCreatorFunc) LPrintout::CreatePrintoutStream);
  83.     URegistrar::RegisterClass(LStdButton::class_ID,        (ClassCreatorFunc) LStdButton::CreateStdButtonStream);
  84.     URegistrar::RegisterClass(LStdCheckBox::class_ID,    (ClassCreatorFunc) LStdCheckBox::CreateStdCheckBoxStream);
  85.     URegistrar::RegisterClass(LStdRadioButton::class_ID,(ClassCreatorFunc) LStdRadioButton::CreateStdRadioButtonStream);
  86.     URegistrar::RegisterClass(LStdPopupMenu::class_ID,    (ClassCreatorFunc) LStdPopupMenu::CreateStdPopupMenuStream);
  87.     URegistrar::RegisterClass(LWindow::class_ID,        (ClassCreatorFunc) LWindow::CreateWindowStream);
  88.  
  89.     URegistrar::RegisterClass(LRadioGroup::class_ID,    (ClassCreatorFunc) LRadioGroup::CreateRadioGroupStream);
  90.     URegistrar::RegisterClass(LActiveScroller::class_ID,(ClassCreatorFunc) LActiveScroller::CreateActiveScrollerStream);
  91.     URegistrar::RegisterClass(LGroupBox::class_ID,        (ClassCreatorFunc) LGroupBox::CreateGroupBoxStream);
  92.  
  93.     // Register custom classes.
  94.     URegistrar::RegisterClass(     CDynamicText::class_ID, (ClassCreatorFunc)     CDynamicText::CreateDynamicTextStream );
  95.     URegistrar::RegisterClass(     CGreyCaption::class_ID, (ClassCreatorFunc)     CGreyCaption::CreateGreyCaptionStream );
  96.     URegistrar::RegisterClass(      CGWorldPane::class_ID, (ClassCreatorFunc)      CGWorldPane::CreateGWorldPaneStream  );
  97.     URegistrar::RegisterClass(LDynamicPopupMenu::class_ID, (ClassCreatorFunc) LDynamicPopupMenu::CreateLDynamicPopupMenuStream    );
  98.     URegistrar::RegisterClass( CMemoryIndicator::class_ID, (ClassCreatorFunc)  CMemoryIndicator::CreateMemoryIndicatorStream    );
  99.     URegistrar::RegisterClass(CDynamicEditField::class_ID, (ClassCreatorFunc) CDynamicEditField::CreateDynamicEditFieldStream    );
  100.  
  101. #ifdef PL_DEBUG
  102.     AddAttachment(new LSIOUXAttachment);    // *** Use SIOUX Attachment
  103. #endif
  104.     mPreferences.FinishCreate();
  105. }
  106.  
  107.  
  108. // ---------------------------------------------------------------------------------
  109. //        • ~CPict2AsciiApp
  110. // ---------------------------------------------------------------------------------
  111. CPict2AsciiApp::~CPict2AsciiApp()
  112. {
  113. }
  114.  
  115.  
  116. // ---------------------------------------------------------------------------------
  117. //        • StartUp
  118. // ---------------------------------------------------------------------------------
  119. void
  120. CPict2AsciiApp::StartUp()
  121. {
  122. //    ObeyCommand (cmd_Open, nil );
  123. }
  124.  
  125.  
  126. // ---------------------------------------------------------------------------------
  127. //        • FindCommandStatus
  128. // ---------------------------------------------------------------------------------
  129. void
  130. CPict2AsciiApp::FindCommandStatus(
  131.     CommandT    inCommand,
  132.     Boolean        &outEnabled,
  133.     Boolean        &outUsesMark,
  134.     Char16        &outMark,
  135.     Str255        outName )
  136. {
  137.     switch ( inCommand ) {
  138.     
  139.         case cmd_New:
  140.             outEnabled = false;
  141.             break;
  142.  
  143.         case cmd_Preferences:
  144.             outEnabled = true;
  145.             break;
  146.  
  147.         default:
  148.         {
  149.             // Call inherited.
  150.             LDocApplication::FindCommandStatus( inCommand,
  151.                 outEnabled, outUsesMark, outMark, outName );
  152.         }
  153.         break;
  154.  
  155.     }
  156. }
  157.  
  158.  
  159.  
  160. // ---------------------------------------------------------------------------
  161. //        • ObeyCommand
  162. // ---------------------------------------------------------------------------
  163. //    Respond to commands
  164.  
  165. Boolean
  166. CPict2AsciiApp::ObeyCommand(
  167.     CommandT    inCommand,
  168.     void        *ioParam)
  169. {
  170.     Boolean        cmdHandled = true;
  171.  
  172.     switch (inCommand) {
  173.     
  174.         case cmd_Preferences:
  175.             mPreferences.DoDialog (mPreferences.GetAllowed());
  176.             
  177.             // No active menus when back from dialog ?
  178.             // In fact, no target at all !
  179.             SwitchTarget(this);
  180.             break;
  181.  
  182.         case cmd_PageSetup:
  183.             SetupPage();
  184.             break;
  185.             
  186.         default:
  187.             cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
  188.             break;
  189.     }
  190.     
  191.     return cmdHandled;
  192. }
  193.  
  194.  
  195. // ---------------------------------------------------------------------------------
  196. //        • OpenDocument (Called in response to the ODOC event)
  197. // ---------------------------------------------------------------------------------
  198. void
  199. CPict2AsciiApp::OpenDocument(
  200.     FSSpec    *inMacFSSpec )
  201. {
  202.     new CDocument (this, inMacFSSpec, &mPreferences);
  203. }
  204.  
  205.  
  206. // ---------------------------------------------------------------------------------
  207. //        • ChooseDocument (called by the "open" menu item)
  208. // ---------------------------------------------------------------------------------
  209. void
  210. CPict2AsciiApp::ChooseDocument()
  211. {
  212.     // Deactivate the desktop.
  213.     UDesktop::Deactivate();
  214.  
  215.     // Browse for a document.
  216.     SFTypeList theList = { 'PICT' };
  217.     StandardFileReply theReply;
  218.     ::StandardGetFilePreview (nil, 1, theList, &theReply);
  219.  
  220.     // Reactivate the desktop.
  221.     UDesktop::Activate();
  222.  
  223.     // Send an apple event to open the file.    
  224.     if (theReply.sfGood)
  225.         SendAEOpenDoc (theReply.sfFile);
  226.  
  227. }
  228.